<template>
<div class="submit_box">
  <a-row :gutter="10">
    <a-col :span="12">
      <TeamItem/>
    </a-col>
    <a-col :span="12">
      <DoTeamItem @submitDoTeamInfoToContest="submitDoTeamInfoToContest"/>
    </a-col>
  </a-row>
</div>
</template>

<script setup lang="ts">
import TeamItem from "@/components/TeamItem.vue";
import DoTeamItem from "@/components/DoTeamItem.vue";
import { onMounted, ref } from "vue";
import { useRoute } from "vue-router";
import { ContestUserControllerService, QuestionControllerService } from "../../generated";
import { Message } from "@arco-design/web-vue";
import router from "@/router";
import { useStore } from "vuex";
import { error } from "echarts/types/src/util/log";

const store = useStore();
const route = useRoute();
const tid = ref();
const contestid = ref();
const userid = ref();
onMounted( async() => {
  contestid.value = route.query?.contestid;
  tid.value = route.query?.id;
  userid.value = store.state.user.curUser.id;
  if (tid.value >= 0) {
    let res = await QuestionControllerService.getQuestionByIdUsingGet(tid.value);
    if (res.code === 0) {
      // 将题目信息赋值
      store.dispatch('team/setCurEditTeam', res.data)
    }else {
      // 跳转失败
      Message.error(res.message);
      // 跳转登录页面
      await router.push({ path: "/user/login" })
    }
  }
})
// 给竞赛添加当前提交记录
const submitDoTeamInfoToContest = async (id) => {
  let res = await ContestUserControllerService.updateSubidsUsingPut({
    subid: id,
    contestid: contestid.value,
    userid: userid.value,
  });
  if (res.code == 0) {
    Message.success("提交成功")
  }else {
    Message.error("提交失败")
  }
}

</script>

<style scoped>
.submit_box {
  min-height: 730px;
}
</style>